package com.cqc.other.juc.synchronize.demo3;

import java.util.concurrent.TimeUnit;

/**
 * @author cui
 * @date 2025/6/25 22:13
 * @description
 **/
public class DataEntity {

    private Object lock = new Object();
    private static int count;

    public void add() {
        synchronized (DataEntity.class) {
        //synchronized (this) {
        //synchronized (lock) {
            for (int i = 0; i < 3; i++) {
                try {
                    System.out.println("threadName:" + Thread.currentThread().getName() + ":" + count++);
                    TimeUnit.MILLISECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public int getCount() {
        return count;
    }
}
